package fr.umlv.jee.jawp.service.configuration;

import java.util.List;

import org.jawp.persistence.Category;
import org.jawp.persistence.CategoryDAO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service("CategoryService")
public class CategoryService {
	@Autowired
	private CategoryDAO dao;

	
	/*************************************
	 *				Creation
	 *************************************/

	@Transactional
	public Category createNewCategory(String name, int motherCategoryId) {
		return dao.createNewCategory(name, motherCategoryId);
	}
	
	@Transactional
	public Category createNewCategory(String name) {
		return dao.createNewCategory(name, -1);
	}

	/*************************************
	 *				Getter
	 *************************************/

	@Transactional(readOnly = true)
	public List<Category> getCategories() {
		return dao.getCategories();
	}
	
	@Transactional(readOnly = true)
	public List<Category> getCategoriesByMotherId(int motherCategoryId) {		 
		return dao.getCategoriesByMotherId(motherCategoryId);
	}
	
	@Transactional(readOnly = true)
	public List<Category> getCategoriesByMotherId() {		 
		return dao.getCategoriesByMotherId(-1);
	}

	@Transactional(readOnly = true)
	public Category getCategoriesById(int id) {		 
		return dao.getCategoriesById(id);
	}

	@Transactional(readOnly = true)
	public Category getCategoryByNameAndMotherCategory(String name, int categoryId) {		 
		return dao. getCategoryByNameAndMotherCategory(name, categoryId);
	}

	@Transactional(readOnly = true)
	public Category getCategoryByNameAndMotherCategory(String name) {		 
		return dao.getCategoryByNameAndMotherCategory(name, -1);
	}
	
	@Transactional(readOnly = true)
	public String getCategoryTreeStructure(Category category){
		return dao.getCategoryTreeStructure(category);
	}

	/*************************************
	 *				Setter
	 *************************************/

	/*************************************
	 *				Deletion
	 *************************************/

	@Transactional
	public void deleteCategory(int id) {
		dao.deleteCategory(id);
	}
}
